home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / term-source.lha / termEmulationProcess.c < prev    next >
C/C++ Source or Header  |  1995-09-26  |  2KB  |  134 lines

  1. /*
  2. **    termEmulationProcess.c
  3. **
  4. **    Terminal emulation process
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. STATIC struct Process *EmulationProcess;
  13.  
  14. STATIC VOID __saveds
  15. EmulationProcessEntry(VOID)
  16. {
  17.     if(TerminalQueue = CreateMsgQueue(NULL,40))
  18.     {
  19.         ULONG         Mask = SIG_KILL | TerminalQueue -> SigMask;
  20.         struct DataMsg    *Msg;
  21.         struct MsgQueue    *Queue = TerminalQueue;
  22.         BOOLEAN         Done = FALSE;
  23.  
  24.         EmulationProcess = (struct Process *)FindTask(NULL);
  25.  
  26.         Signal(ThisProcess,SIG_HANDSHAKE);
  27.  
  28.         do
  29.         {
  30.             if(Wait(Mask) & SIG_KILL)
  31.             {
  32.                 Forbid();
  33.  
  34.                 TerminalQueue = NULL;
  35.  
  36.                 Permit();
  37.  
  38.                 break;
  39.             }
  40.  
  41.             ObtainSemaphore(&TerminalSemaphore);
  42.  
  43.             ClearCursor();
  44.  
  45.             while(Msg = GetMsgItem(TerminalQueue))
  46.             {
  47.                     /* Remember the data. */
  48.  
  49.                 if(RememberOutput)
  50.                     RememberOutputText(Msg -> Data,Msg -> Size);
  51.  
  52.                 (*ConProcessData)(Msg -> Data,Msg -> Size);
  53.  
  54.                 DeleteMsgItem(Msg);
  55.  
  56.                 if(SetSignal(0,0) & SIG_KILL)
  57.                 {
  58.                     Forbid();
  59.  
  60.                     TerminalQueue = NULL;
  61.  
  62.                     Permit();
  63.  
  64.                     Done = TRUE;
  65.  
  66.                     break;
  67.                 }
  68.             }
  69.  
  70.             DrawCursor();
  71.  
  72.             ReleaseSemaphore(&TerminalSemaphore);
  73.         }
  74.         while(!Done);
  75.  
  76.         while(Msg = GetMsgItem(Queue))
  77.             DeleteMsgItem(Msg);
  78.  
  79.         DeleteMsgQueue(Queue);
  80.     }
  81.  
  82.     Forbid();
  83.  
  84.     EmulationProcess = NULL;
  85.  
  86.     Signal(ThisProcess,SIG_HANDSHAKE);
  87. }
  88.  
  89. VOID
  90. DeleteEmulationProcess()
  91. {
  92.     if(EmulationProcess)
  93.     {
  94.         Forbid();
  95.  
  96.         Signal(EmulationProcess,SIG_KILL);
  97.  
  98.         ClrSignal(SIG_HANDSHAKE);
  99.  
  100.         Wait(SIG_HANDSHAKE);
  101.  
  102.         Permit();
  103.     }
  104. }
  105.  
  106. BOOLEAN
  107. CreateEmulationProcess()
  108. {
  109.     if(!EmulationProcess)
  110.     {
  111.         Forbid();
  112.  
  113.         if(CreateNewProcTags(
  114.             NP_Name,    "term Emulation Process",
  115.             NP_Priority,    SysBase -> ThisTask -> tc_Node . ln_Pri,
  116.             NP_Entry,    EmulationProcessEntry,
  117.             NP_StackSize,    6000,
  118.             NP_WindowPtr,    Window,
  119.         TAG_DONE))
  120.         {
  121.             ClrSignal(SIG_HANDSHAKE);
  122.  
  123.             Wait(SIG_HANDSHAKE);
  124.         }
  125.  
  126.         Permit();
  127.     }
  128.  
  129.     if(EmulationProcess)
  130.         return(TRUE);
  131.     else
  132.         return(FALSE);
  133. }
  134.